﻿using System;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Text;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a document type control. 
    /// </summary>
    public class UIDocument : UIBaseControl
    {
        /// <summary>
        /// Gets a value which indicates whether the control can scroll horizontally. 
        /// </summary>
        public new bool HorizontallyScrollable
        {
            get { return base.HorizontallyScrollable; }
        }

        /// <summary>
        /// Gets a value which indicates whether the control can scroll horizontally. 
        /// </summary>
        public new bool VerticallyScrollable
        {
            get { return base.VerticallyScrollable; }
        }

        /// <summary>
        /// Gets the value of the horizontal scroll position.
        /// If the control does not support the <see cref="ScrollPattern"/>, returns NaN. 
        /// </summary>
        public new double HorizontalScrollPercent
        {
            get { return base.HorizontalScrollPercent; }
        }

        /// <summary>
        /// Gets the value of the vertical scroll position 
        /// If the control does not support the <see cref="ScrollPattern"/>, returns NaN.
        /// </summary>
        public new double VerticalScrollPercent
        {
            get { return base.VerticalScrollPercent; }
        }

        /// <summary>
        /// Gets the value of the horizontal size of the viewable region.
        /// If the control does not support the <see cref="ScrollPattern"/>, returns NaN.
        /// </summary>
        public new double HorizontalViewSize
        {
            get { return base.HorizontalViewSize; }
        }

        /// <summary>
        /// Gets the value of the vertical size of the viewable region.
        /// If the control does not support the <see cref="ScrollPattern"/>, returns NaN.
        /// </summary>
        public new double VerticalViewSize
        {
            get { return base.VerticalViewSize; }
        }

        /// <summary>
        /// Gets or sets the current value of the document if it supports it. 
        /// </summary>
        public new string Value
        {
            get { return base.Value; }
            set
            {
                base.SetValue(value);
            }
        }

        /// <summary>
        /// Gets the text range that encloses the main text of a document. 
        /// </summary>
        public new TextPatternRange DocumentRange
        {
            get { return base.DocumentRange; }
        }

        /// <summary>
        /// Gets a value that indicates the type of text selection that is supported by the control. 
        /// </summary>
        public new SupportedTextSelection SupportedTextSelection
        {
            get { return base.SupportedTextSelection; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class. 
        /// </summary>
        public UIDocument(): base(ControlType.Document)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UIDocument(UIBaseControl parent) : base(parent, ControlType.Document)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIDocument(string locator) : base(null, ControlType.Document, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIDocument(UIBaseControl parent, string locator) : base(parent, ControlType.Document, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIDocument(AutomationElement control) : base(control, ControlType.Document)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIDocument"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIDocument(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.Document)
        {
        }

        /// <summary>
        /// Scrolls the visible region of the content area horizontally and vertically. 
        /// </summary>
        /// <param name="horizontalAmount">The horizontal scrolling increment that is specific to the control.</param>
        /// <param name="verticalAmount">The vertical scrolling increment that is specific to the control.</param>
        public new void Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
        {
            base.Scroll(horizontalAmount, verticalAmount);
        }

        /// <summary>
        /// Sets the horizontal and/or vertical scroll of the document.  
        /// </summary>
        /// <param name="horizontalPercent">
        /// The percentage of the total horizontal content area. 
        /// NoScroll should be passed in if the control cannot be scrolled in this direction.
        /// </param>
        /// <param name="verticalPercent">
        /// The percentage of the total vertical content area. 
        /// NoScroll should be passed in if the control cannot be scrolled in this direction.
        /// </param>
        public new void SetScrollPercent(double horizontalPercent, double verticalPercent)
        {
            base.SetScrollPercent(horizontalPercent, verticalPercent);
        }

        /// <summary>
        /// Scrolls the visble region of the content area vertically by a <see cref="ScrollAmount"/>.
        /// </summary>
        /// <param name="scrollAmount">The vertical scrolling increment.</param>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void ScrollVertically(ScrollAmount scrollAmount)
        {
            base.ScrollVertically(scrollAmount);
        }

        /// <summary>
        /// Scrolls the visble region of the content area horizontally by a <see cref="ScrollAmount"/>.
        /// </summary>
        /// <param name="scrollAmount">The horizontal scrolling increment.</param>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void ScrollHorizontally(ScrollAmount scrollAmount)
        {
            base.ScrollHorizontally(scrollAmount);
        }

        /// <summary>
        /// Retrieves a collection of text ranges that represents the currently selected text in a text-based control
        /// </summary>
        /// <returns>A collection of disjoint text ranges.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange[] GetTextSelection()
        {
            return base.GetTextSelection();
        }

        /// <summary>
        /// Retrieves an array of disjoint text ranges from a text-based control where each text range represents a contiguous span of visible text.
        /// </summary>
        /// <returns>The collection of visible text ranges within the container or an empty array.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange[] GetVisibleRanges()
        {
            return base.GetVisibleRanges();
        }

        /// <summary>
        /// Retrieves a text range enclosing a child element such as an image, hyperlink, Microsoft Excel spreadsheet, or other embedded object. 
        /// </summary>
        /// <returns>A range that spans the child element.</returns>
        /// <exception cref="ArgumentNullException">The child element is null.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange RangeFromChild(AutomationElement childElement)
        {
            return base.RangeFromChild(childElement);
        }

        /// <summary>
        /// Returns the degenerate (empty) text range nearest to the specified screen coordinates. 
        /// </summary>
        /// <param name="screenLocation">The location in screen coordinates.</param>
        /// <returns>A degenerate range nearest the specified location. Null is never returned.</returns>
        /// <exception cref="ArgumentException">A given point is outside the <see cref="AutomationElement"/> associated with the text pattern.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange RangeFromPoint(Point screenLocation)
        {
            return base.RangeFromPoint(screenLocation); 
        }

        /// <summary>
        /// Inserts a string into a control that supports the value pattern. 
        /// </summary>
        /// <param name="value">The string to be inserted.</param>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void SetValue(string value)
        {
           SetValue(value);
        }
    }
}
